package com.packagetracker.carriers.handlers;

import java.io.Serializable;

import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;

import com.google.android.maps.MapActivity;
import com.packagetracker.carriers.PackageActivity;
import com.packagetracker.carriers.PackageDetails;
import com.packagetracker.carriers.PackageLocation;
import com.packagetracker.carriers.ParsedDataSet;

public abstract class PackageHandler extends DefaultHandler implements Serializable {
	
	private static final long serialVersionUID = -7316897591337927050L;
	
	private MapActivity mapActivity;
	private PackageActivity packageActivity;
	private PackageLocation location;
	private PackageDetails details;
	private ParsedDataSet dataSet;
	private String tag = "";
	
	public abstract void parsePackageActivity(final MapActivity activity, final String number);
	
	public MapActivity getMapActivity() {
		return this.mapActivity;
	}
	
	public PackageActivity getPackageActivity() {
		return ((this.packageActivity == null) ? new PackageActivity() : this.packageActivity);
	}
	
	public PackageLocation getPackageLocation() {
		return ((this.location == null) ? new PackageLocation() : this.location);
	}
	
	public PackageDetails getPackageDetails() {
		return ((this.details == null) ? new PackageDetails() : this.details);
	}
	
	public ParsedDataSet getDataSet() {
		return ((this.dataSet == null) ? new ParsedDataSet() : this.dataSet);
	}
	
	public String getTag() {
		return this.tag;
	}
	
	public void setMapActivity(final MapActivity mapActivity) {
		this.mapActivity = mapActivity;
	}
	
	public void setPackageLocation(final PackageLocation location) {
		this.location = location;
	}
	
	public void setPackageDetails(final PackageDetails details) {
		this.details = details;
	}
	
	public void setTag(final String tag) {
		this.tag = tag;
	}
	
	@Override
	public void startDocument() throws SAXException {
		this.packageActivity = new PackageActivity();
		this.dataSet = new ParsedDataSet();
	}
	
	@Override
	public void error(final SAXParseException exception) throws SAXException {
		throw exception;
	}
	
}